//
//  PieChartTableCellView.m
//  MoneyLog
//
//  Created by Max on 11-6-12.
//  Copyright 2011年 wicresoft. All rights reserved.
//

#import "PieChartTableCellView.h"
#import "PieChartItem.h"

@implementation PieChartTableCellView
@synthesize item;

- (id)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        // Initialization code
         self.backgroundColor=[UIColor whiteColor];
    }
    return self;
}


// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect
{
    // Drawing code
    CGContextRef context = UIGraphicsGetCurrentContext();
	//抗锯齿
	CGContextSetAllowsAntialiasing(context, TRUE);
    
	CGContextMoveToPoint(context, 0, 0);
	CGContextSaveGState(context);
    CGContextRestoreGState(context);
    
    float origionx = 10 ;
    float origiony = 10 ;
    
    [item.color setFill];

    CGContextFillRect(context, CGRectMake(origionx, origiony+3, 15, 15));
    CGContextDrawPath(context, kCGPathFill);
    
    [item.title drawAtPoint:CGPointMake(origionx + 30, origiony) withFont:[UIFont systemFontOfSize:16]];
    [[NSString stringWithFormat:@"%d 元",item.value] drawAtPoint:CGPointMake(origionx + 80, origiony) withFont:[UIFont systemFontOfSize:16]];
    [[NSString stringWithFormat:@"%.2f %%",item.percent*100] drawAtPoint:CGPointMake(origionx + 180, origiony) withFont:[UIFont systemFontOfSize:16]];
}

- (void)dealloc
{
    [item release];
    [super dealloc];
}

@end
